<?php

namespace app\api\controller;

use app\facade\Redis;
use app\facade\Mns;
use think\Validate;
use think\Facade\Config as Configs;
use think\Db;
use oss\Oss;

class Other extends Base
{
    //发送短信
    public function sendMns()
    {
        $data = $this->request->post();
        $validate = new Validate([
            'mobile' => 'require',
        ], [
            'mobile.require' => '手机号码必须填写',
        ]);
        if (!$validate->check($data)) {
            $this->result([], 1, $validate->getError());
        }
        $CheckCode = (new Mns)->send($data['mobile']);
        if (!$CheckCode) {
            $this->result([], 1, $CheckCode['msg']);
        }
        $this->result([], 0, $CheckCode['msg']);
    }

    public function uploads()
    {
        if ($this->request->isPost()) {
            $file = request()->file('file');
            $path =  $_SERVER['DOCUMENT_ROOT'] . "/uploads/";
            $info = $file->validate(['size' => 1024 * 1024 * 5, 'ext' => 'jpg,png,gif,jpeg'])
                ->move($path);
            if (!$info) {
                $this->result([], 1, $file->getError());
            } else {
                $url = '/uploads' . '/' . $info->getSaveName();
                $url = url($url, '', '', true);
                $this->result($url, 0, '上传成功');
            }
        }
    }
}
